import React, { Component } from 'react';
import '../../../../css.css'
class CommentHeader extends Component {
  state = {
    title: '',
    content: '',
  }
  //  评论人
  updateTitle = (e) => {
    console.log(e.target.value);
    // 从事件对象event中拿到input的值来更新state
    let title = e.target.value
    // 更新state-> setState方法
    this.setState({
      title
    })
  }

  // 评论内容
  updateContent = (e) => {
    // 从事件对象event中拿到input的值来更新state
    this.setState({
      content: e.target.value
    })
  }

  // 发布评论
  pushList = () => {
    const { title, content } = this.state
    console.log(title,content);
    this.props.updateList({title,content})
    this.setState({
      title:'',
      content:''
    })
  }

  
  render () {
    return (<>
      <div style={{ textAlign: 'center' }}>
        <div className='inputbox'>
          <input value={this.state.title} className='input' type="text" placeholder='请输入评论人' onChange={this.updateTitle} />
        </div>
        <div className='textbox'>
          <textarea name="" id="" cols="30" rows="10" placeholder='请输入评论内容' value={this.state.content} onChange={this.updateContent}></textarea>
        </div>
        <button className='button' onClick={this.pushList}>发表评论</button>
        <button onClick={()=>this.props.delArr}>清空</button>
      </div>
    </>);
  }
}

export default CommentHeader;